<template>
  <div class="full-page">
    <!-- 缓存当前router-view装载的Cate/Cart/Mine组件 -->
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
    <!-- <router-view></router-view> -->
    <tab-bar></tab-bar>
  </div>
</template>

<script>
import TabBar from '../components/tab-bar.vue'
import { mapState } from 'vuex'
export default {
  name: 'root',
  components: {
    [TabBar.name]: TabBar
  },
  computed: {
    ...mapState('user', ['isLogin'])
  },
  watch: {
    //未登录状态直接进入登录页面
    isLogin(newValue) {
      if (!newValue) {
        this.$router.replace('/login');

      }
    }
  },
  created() {
    // 登录状态为true，还需要验证。
    if(this.isLogin){
      this.$store.dispatch("user/checkLoginAction");
    }
  }
};
</script>
<style scoped></style>


